package com.telit.uav.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.telit.uav.dao.CommUavDao;
import com.telit.uav.dao.CommUavReportInfoMapper;
import com.telit.uav.entity.CommUavReportInfo;
import com.telit.uav.service.CommUavReportInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;


/**
 * 新增无人机故障维修上报记录
 */
@Service
public class CommUavReportInfoServiceImpl extends ServiceImpl<CommUavReportInfoMapper, CommUavReportInfo> implements
        CommUavReportInfoService {

    @Autowired
    private CommUavDao commUavDao;

    @Transactional
    @Override
    public void add(CommUavReportInfo commUavReportInfo) {
        commUavReportInfo.setReportTime(new Date());
        baseMapper.insert(commUavReportInfo);
        Integer reportType = commUavReportInfo.getReportType();
        Long uavId = commUavReportInfo.getUavId();
        if (reportType.equals(2)) {
            //上报类型为维修 无人机健康状态设置为正常
            commUavDao.updateHealthStatus(0,uavId);
        } else {
            //更新无人机健康状态 (1:损坏 2：报废)
            Integer faultType = commUavReportInfo.getFaultType();
            if (faultType != null) {
                commUavDao.updateHealthStatus(faultType,uavId);
            }
        }
    }
}
